//
//  WGQHomeAlertView.m
//  MaYi
//
//  Created by 小破夕 on 2018/9/8.
//  Copyright © 2018年 JUMI. All rights reserved.
//  首页弹出的视图

#import "WGQTransfersRecordsAlertView.h"
#import "WGQTransfersRecordsAlertTableViewCell.h"
#import "UIView+ShowView.h"

@interface WGQTransfersRecordsAlertView ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView * tableView;
@property (nonatomic,strong) NSMutableArray * tableArray;

@end

@implementation WGQTransfersRecordsAlertView

- (instancetype)initWithFrame:(CGRect)frame andTitleArray:(NSArray *)titleArray
{
    if (self = [super initWithFrame:frame])
    {
        self.tableArray = [NSMutableArray arrayWithArray:titleArray];
        [self addSubViews];
    }
    return self;
}

- (void)addSubViews
{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    if (@available(iOS 11.0, *))
    {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    self.tableView.backgroundColor = FFColor(0xebebeb);
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.estimatedRowHeight = 0;
    self.tableView.estimatedSectionHeaderHeight = 0;
    self.tableView.estimatedSectionFooterHeight = 0;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerClass:[WGQTransfersRecordsAlertTableViewCell class] forCellReuseIdentifier:[NSString stringWithUTF8String:object_getClassName([WGQTransfersRecordsAlertTableViewCell class])]];
    [self addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.top.equalTo(self.mas_top);
         make.left.equalTo(self.mas_left);
         make.right.equalTo(self.mas_right);
         make.bottom.equalTo(self.mas_bottom);
     }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.tableArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WGQTransfersRecordsAlertTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:[NSString stringWithUTF8String:object_getClassName([WGQTransfersRecordsAlertTableViewCell class])] forIndexPath:indexPath];
    [cell setObject:self.tableArray[indexPath.row]];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40 * kScale;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (self.click_index_block)
    {
        self.click_index_block(indexPath.row);
    }
    [self dismiss];
}
@end
